package com.fortune.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fortune.common.paging.PagingData;
import com.fortune.dao.MUserMgtDao;
import com.fortune.dto.in.mUserMgt.MUserAddDto;
import com.fortune.dto.in.mUserMgt.MUserEditDto;
import com.fortune.dto.in.mUserMgt.MUserListDto;
import com.fortune.dto.in.mUserMgt.MUserLogableDto;
import com.fortune.entity.MUserInfo;
import com.fortune.service.MUserMgtService;
import com.fortune.vo.mUserMgt.User;
@Service
public class MUserMgtServiceImpl implements MUserMgtService{
	@Autowired
	private MUserMgtDao mUserMgtDao;
	@Override
	public int addMUser(MUserInfo mUserInfo, MUserAddDto addDto) {
		int checkPhone = mUserMgtDao.checkPhone(mUserInfo, addDto); 
		if(checkPhone>0)
			return 2;
		int checkNumber = mUserMgtDao.checkNumber(mUserInfo, addDto);
		if(checkNumber>0)
			return 3;
		int add = mUserMgtDao.addMUser(mUserInfo, addDto);
		return add;
	}
	@Override
	public PagingData<User> pagingData(MUserInfo mUserInfo, MUserListDto listDto) {
		List<User> list = mUserMgtDao.list(mUserInfo, listDto);
		int count = mUserMgtDao.count(mUserInfo, listDto);
		PagingData<User> pagingData = new PagingData<>(list,count);
		return pagingData;
	}
	@Override
	public int edit(MUserInfo mUserInfo, MUserEditDto editDto) {
		int checkUser = mUserMgtDao.checkUser(mUserInfo, editDto);
		if (checkUser==0) {
			return 2;
		}
		int checkEditPhone = mUserMgtDao.checkEditPhone(mUserInfo, editDto);
		if (checkEditPhone>0) {
			return 3;
		}
		int edit = mUserMgtDao.edit(mUserInfo, editDto);
		return edit;
	}
	@Override
	public int delete(MUserInfo mUserInfo, String userId) {
		int delete = mUserMgtDao.delete(mUserInfo, userId);
		return delete;
	}
	@Override
	public int resetPassword(MUserInfo mUserInfo, String userId) {
		int reset = mUserMgtDao.resetPassword(mUserInfo, userId);
		return reset;
	}
	@Override
	public int setLogin(MUserInfo mUserInfo, MUserLogableDto logableDto) {
		int set = mUserMgtDao.set(mUserInfo, logableDto);
		return set;
	}

}
